﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using Hi_Baidu.Remote;
using UMFramework.UI.Compoment;
using Hi_Baidu.FileShare.User;
using System.Windows.Media.Imaging;
using Hi_Baidu.Model.ViewModel;
using Hi_Baidu.Model.ProcessModel;
using Hi_Biadu.UI.PersonalObject;

namespace Hi_Baidu.FileShare
{
	public partial class Window1
	{
        private delegate void DELEGATE_ADDUSER(FileShareUser user);
		public Window1()
		{
			this.InitializeComponent();
			
			// 在此点之下插入创建对象所需的代码。
		}

        private void Win_FileShare_Loaded(object sender, RoutedEventArgs e)
        {
            //注册通道
            //RemoteConnect.RegisterChannel(Directory.GetCurrentDirectory() + "/../../../FileShare/FileShare/bin/Debug/FileShare.exe.config");
            //FileShareProcessor.CreateUserEventArgs += new CreateFileShareUser(FileShareProcessor_CreateUserEventArgs);
            //加载驱动器
            Image img = new Image();
            img.Source = new BitmapImage(new Uri("pack://application:,,,/SysImage/2007641629508.png"));
            IOViewModel.InitDrive(this.TV_Disk, IOProcessModel.GetDriveInfo(), img);
            Image Fimg = new Image();
            Fimg.Source = new BitmapImage(new Uri("pack://application:,,,/SysImage/2007641624645.png"));
            //加载首层目录
            foreach (IOTreeViewItem item in this.TV_Disk.Items)
            {
                IOViewModel.SetDirectory(item, IOProcessModel.GetDirectory((item.Header as StackPanel).Tag.ToString()), Fimg);
                IOViewModel.SetFile(item, IOProcessModel.GetFiles((item.Header as StackPanel).Tag.ToString()));
            }
        }

        void FileShareProcessor_CreateUserEventArgs(object Sender, FileShareEventArgs e)
        {
            System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new DELEGATE_ADDUSER(AddUser), e.User as FileShareUser);
        }

        public void AddUser(FileShareUser user)
        {
            UserGroupButton ugb = new UserGroupButton();
            ugb.Width = 175;
            ugb.Height = 205;
            ugb.Text = user.Key;
            this.WP_UserGroup.Children.Add(ugb);
        }

        private void UserGroupButton_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Storyboard storyborad = this.FindResource("SB_UserInto") as Storyboard;
            storyborad.Begin(this);
            this.Gd_Head.Visibility = Visibility.Collapsed;
            this.Gd_Main.Visibility = Visibility.Collapsed;
        }
	}
}